<?php
require_once("models/NguoiDung.php");

class SinhVien extends NguoiDung {
	private $maLop;
	private $tenDVDT;
	private $maKhoaHoc;
	private $namBatDau;
	private $nganh;
	
	public function __construct($new = false) {
		parent::__construct($new);
		$this->prefix = "SV_";
		$this->table = "SINH_VIEN";
	}
	
	public function getMaLop() { return $this->maLop; }
	public function getTenDVDT() { return $this->tenDVDT; }
	public function getMaKhoaHoc() { return $this->maKhoaHoc; }
	public function getNamBatDau() { return $this->namBatDau; }
	public function getNganh() { return $this->nganh; }
	
	public function themSinhVien() {
		return $this->themNguoiDung();
	}
	
	public function suaSinhVien() {
		return $this->suaNguoiDung();
	}
	
	public function xoaSinhVien() {
		return $this->xoaNguoiDung();
	}
		
	public function layThongTinNguoiDung() {
		$data = array(
					$this->prefix . "HO as HO",
					$this->prefix . "TEN as TEN",
					"date_format(" . $this->prefix . "NGAY_SINH, '%d-%m-%Y') as NGAY_SINH",
					$this->prefix . "PHAI as PHAI",
					$this->prefix . "EMAIL as EMAIL",
					"DVDT_TEN", "L.LOP_MA_SO", "K.KH_MA_SO", "NGANH_TEN",
					"date_format(K.KH_NAM_BAT_DAU, '%Y') as NAM_BAT_DAU"
					);
		
		$where = $this->prefix . "MA_SO = " . $this->maSo
		       . " AND S.LOP_MA_SO = L.LOP_MA_SO AND L.DVDT_MA_SO = D.DVDT_MA_SO "
			   . " AND L.KH_MA_SO = K.KH_MA_SO AND L.NGANH_MA_SO = N.NGANH_MA_SO";
		
		$result = $this->select($this->table . " S, LOP L, KHOA_HOC K, NGANH N, DON_VI_DAO_TAO D", $data, $where);		
		$row = mysql_fetch_assoc($result);
		$this->ho = $row['HO'];
		$this->ten = $row['TEN'];
		$this->ngaySinh = $row['NGAY_SINH'];
		$this->phai = $row['PHAI'];
		$this->email = $row['EMAIL'];
		$this->maLop = $row['LOP_MA_SO'];
		$this->maKhoaHoc = $row['KH_MA_SO'];
		$this->namBatDau = $row['NAM_BAT_DAU'];
		$this->tenDVDT = $row['DVDT_TEN'];
		$this->nganh = $row['NGANH_TEN'];
	}
	
	public function layThongTinSinhVienTheoQuyen($quyen, $maNguoiDung) {
		if ($quyen == "CVHT_") {
			$this->setQuery("SELECT SV_MA_SO FROM SINH_VIEN A, LOP B "
						   . "WHERE A.SV_MA_SO = " . $this->maSo . " AND A.LOP_MA_SO = B.LOP_MA_SO "
						   . "AND B.CVHT_MA_SO = " . $maNguoiDung);
		} else {
			$this->setQuery("SELECT SV_MA_SO FROM SINH_VIEN A, LOP B, HOI_DONG_KHOA C "
						   . "WHERE A.SV_MA_SO = " . $this->maSo . " AND A.LOP_MA_SO = B.LOP_MA_SO "
						   . "AND B.DVDT_MA_SO = C.DVDT_MA_SO AND C.HDK_MA_SO = " . $maNguoiDung);
		}
		
		if ($this->numRecord()) {
			$this->layThongTinNguoiDung();
			return true;
		} else return false;
	}
}
?>